package com.chiancloud.shield.common.params;

import com.beust.jcommander.Parameter;
import com.chiancloud.shield.core.exception.BadCommandArgumentsException;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class AppAndResouceOptionArgsDelegate extends AbstractArgsDelegate {


    @Parameter(names = {ARG_OPTION, ARG_OPTION_SHORT}, arity = 2,
            description = ARG_OPTION + "<name> <value>",
            splitter = DontSplitArguments.class)
    public List<String> optionTuples = new ArrayList<>(0);


    @Parameter(names = {ARG_COMP_OPT, ARG_COMP_OPT_SHORT, ARG_ROLEOPT}, arity = 3,
            description = "Component option " + ARG_COMP_OPT +
                    " <component> <name> <option>",
            splitter = DontSplitArguments.class)
    public List<String> compOptTriples = new ArrayList<>(0);


    @Parameter(names = {ARG_RESOURCE_OPT, ARG_RESOURCE_OPT_SHORT}, arity = 2,
            description = "Resource option " + ARG_RESOURCE_OPT + "<name> <value>",
            splitter = DontSplitArguments.class)
    public List<String> resOptionTuples = new ArrayList<>(0);


    @Parameter(names = {ARG_RES_COMP_OPT, ARG_RES_COMP_OPT_SHORT,}, arity = 3,
            description = "Component resource option " + ARG_RES_COMP_OPT +
                    " <component> <name> <option>",
            splitter = DontSplitArguments.class)
    public List<String> resCompOptTriples = new ArrayList<>(0);


    public Map<String, String> getOptionsMap() throws
            BadCommandArgumentsException {
        return convertTupleListToMap(ARG_OPTION, optionTuples);
    }


    public Map<String, Map<String, String>> getCompOptionMap() throws
            BadCommandArgumentsException {
        return convertTripleListToMaps(ARG_COMP_OPT, compOptTriples);
    }

    public Map<String, String> getResourceOptionsMap() throws
            BadCommandArgumentsException {
        return convertTupleListToMap(ARG_RESOURCE_OPT, resOptionTuples);
    }


    public Map<String, Map<String, String>> getResourceCompOptionMap() throws
            BadCommandArgumentsException {
        return convertTripleListToMaps(ARG_COMP_OPT, resCompOptTriples);
    }

    public void setOption(String key, String value) {
        optionTuples.add(key);
        optionTuples.add(value);
    }

    public void setResourceOption(String key, String value) {
        resOptionTuples.add(key);
        resOptionTuples.add(value);
    }

}
